package com.jjb.www.ui.fragment;

import android.content.Intent;
import android.util.Log;
import android.view.View;

import com.baidu.ocr.ui.camera.CameraActivity;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.layout.ShapeRelativeLayout;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.aop.SingleClick;
import com.jjb.www.app.TitleBarFragment;
import com.jjb.www.http.api.AgencyListApi;
import com.jjb.www.http.api.RefreshTokenApi;
import com.jjb.www.http.api.UserInfoApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.other.AppConfig;
import com.jjb.www.ui.activity.ArchivesActivity;
import com.jjb.www.ui.activity.DryRrunActivity;
import com.jjb.www.ui.activity.HistoryListActivity;
import com.jjb.www.ui.activity.HomeActivity;
import com.jjb.www.ui.activity.MineMessageActivity;
import com.jjb.www.ui.activity.PaymentListActivity;
import com.jjb.www.ui.activity.PersonalDataActivity;
import com.jjb.www.ui.activity.SettingActivity;
import com.jjb.www.utils.FileUtil;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/10/18
 *    desc   : 我的 Fragment
 */
public final class MineFragment extends TitleBarFragment<HomeActivity> {
    private static final int REQUEST_CODE_CAMERA = 102;
    private ShapeImageView mImgHead;
    private ShapeTextView mTvNickname;
    private ShapeImageView mImgIsAuth;
    private ShapeTextView mTvIsAuth;
    private ShapeRelativeLayout mRlMessage;





    public static MineFragment newInstance() {
        return new MineFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.mine_fragment;
    }

    @Override
    protected void initView() {
        mImgHead = findViewById(R.id.img_head);
        mTvNickname = findViewById(R.id.tv_nickname);
        mImgIsAuth = findViewById(R.id.img_is_auth);
        mTvIsAuth = findViewById(R.id.tv_is_auth);
        mRlMessage = findViewById(R.id.rl_message);
        setOnClickListener(R.id.rl_message,R.id.ll_personal,R.id.set_bar_record,R.id.set_bar_history,R.id.set_bar_archives,R.id.set_bar_payment,R.id.set_bar_service,R.id.set_bar_setting);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onResume() {
        super.onResume();
//        getUserInfo();
        getRefreshToken();
    }

    private void getRefreshToken() {
        EasyHttp.post(this)
                .api(new RefreshTokenApi()
                .setUser_id(AppConfig.getInstance().getUserBean().getUser().getId()+""))
                .request(new HttpCallback<HttpData<RefreshTokenApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<RefreshTokenApi.Bean> data) {
                        GlideApp.with(getActivity())
                                .load(data.getData().getUser().getImg())
                                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                                .into(mImgHead);
                        mTvNickname.setText(data.getData().getUser().getNickname());
                        if (data.getData().getUser().getIs_auth()==0){
                            //未实名
                            GlideApp.with(getActivity())
                                    .load(R.mipmap.icon_mine_wsm)
                                    .into(mImgIsAuth);
                            mTvIsAuth.setText("未实名");
                        }else if (data.getData().getUser().getIs_auth()==1){
                            //待审核
                            GlideApp.with(getActivity())
                                    .load(R.mipmap.icon_mine_rzz)
                                    .into(mImgIsAuth);
                            mTvIsAuth.setText("认证中");
                        }else if (data.getData().getUser().getIs_auth()==2){
                            //审核成功
                            GlideApp.with(getActivity())
                                    .load(R.mipmap.icon_mine_ysm)
                                    .into(mImgIsAuth);
                            mTvIsAuth.setText("已实名");
                        }else {
                            //审核失败
                            GlideApp.with(getActivity())
                                    .load(R.mipmap.icon_mine_rzbtg)
                                    .into(mImgIsAuth);
                            mTvIsAuth.setText("认证不通过");
                        }
                    }
                });
    }

    @SingleClick
    @Override
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId==R.id.ll_personal){
            startActivity(PersonalDataActivity.class);
        }else if (viewId==R.id.set_bar_record){
            //模考记录
            startActivity(DryRrunActivity.class);
        }else if (viewId==R.id.set_bar_history){
            //培训历史
            startActivity(HistoryListActivity.class);
        }else if (viewId==R.id.set_bar_archives){
            //电子档案
            startActivity(ArchivesActivity.class);
        }else if (viewId==R.id.set_bar_payment){
            //支付记录
            startActivity(PaymentListActivity.class);
        }else if (viewId==R.id.set_bar_service){
            //我的客服

        }else if (viewId==R.id.rl_message){
            //消息
            startActivity(MineMessageActivity.class);
        }
        else if (viewId==R.id.set_bar_setting){
            //设置
            startActivity(SettingActivity.class);
        }
    }
    @Override
    public boolean isStatusBarEnabled() {
        // 使用沉浸式状态栏
        return !super.isStatusBarEnabled();
    }
}